﻿<RadioButton x:Class="Shatranj.BoardSquareView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Shatranj="clr-namespace:Shatranj">
    <!--IsEnabled="{Binding IsEnabled}"-->

    <RadioButton.Resources>
        <Shatranj:ForceToGroupNameConverter x:Key="ForceToGroupNameConverter" />
        <Style TargetType="{x:Type Shatranj:BoardSquareView}">
            <Setter Property="IsChecked" Value="false" />
            <!--<Setter Property="DataContext" Value="{Binding CurrentSquare}"/>-->

            <Setter Property="Background"
                    Value="{Binding Path=CurrentSquare, Converter={StaticResource LocationToColorConverter}, 
                              Mode=OneWay}" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="GroupName"
                    Value="{Binding Path=CurrentSquare, Converter={StaticResource ForceToGroupNameConverter}}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Shatranj:BoardSquareView}">
                        <ControlTemplate.Resources>
                            <Style TargetType="RadioButton">
                                <Setter Property="Background"
                                        Value="{Binding Path=CurrentSquare, Converter={StaticResource LocationToColorConverter}, 
                                        Mode=OneWay}" />
                            </Style>
                            <Shatranj:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
                        </ControlTemplate.Resources>

                        <Grid DataContext="{Binding CurrentSquare}" Background="{TemplateBinding  Background}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.200*" />
                                <RowDefinition Height="0.800*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Border BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" />
                            <Viewbox Grid.Row="0" Grid.Column="0"
                                     HorizontalAlignment="Right" VerticalAlignment="Stretch">
                                <TextBlock FontSize="12"
                                           FontFamily="Consolas"
                                           Text="{Binding Path=AlgebraicIdentity, Mode=OneWay}" />
                            </Viewbox>
                            <Viewbox Grid.RowSpan="2" Grid.Row="0"
                                     HorizontalAlignment="Center" VerticalAlignment="Center">
                                <TextBlock FontFamily="Chess Cases"
                                           Margin="3,3,3,3"
                                           Text="{Binding Path=CurrentPiece.AltChar, 
                                          Mode=OneWay}" />
                            </Viewbox>

                            <Ellipse
                                MaxHeight="30" MaxWidth="30"
                                MinHeight="10" MinWidth="10"
                                Grid.Row="0" Grid.RowSpan="2"
                                Visibility="{Binding IsHit, 
																		Converter={StaticResource BoolToVisibilityConverter}}">
                                <Ellipse.Fill>
                                    <SolidColorBrush Color="Black" Opacity="0.5" />
                                </Ellipse.Fill>
                            </Ellipse>

                        </Grid>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Foreground" Value="Red" />
                                <Setter Property="Background" Value="Black" />
                                <Setter Property="BorderBrush" Value="Red" />
                                <Setter Property="BorderThickness" Value="2" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Background" Value="DarkBlue" />
                    <Setter Property="Foreground" Value="LightGreen" />
                    <Setter Property="BorderBrush" Value="LightGreen" />
                    <Setter Property="BorderThickness" Value="2" />
                    <Setter Property="CommandParameter" Value="{Binding}" />
                    <Setter Property="Command" Value="{Binding Parent.PieceSelectedHandler}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </RadioButton.Resources>
</RadioButton>